package cn.rxmind.dlicense.core.validator;

import cn.rxmind.dlicense.core.base.DLicenseContent;
import cn.rxmind.dlicense.core.utils.MachineInfoUtil;
import lombok.Setter;

import java.util.Objects;
import java.util.Set;

/**
 * IP 地址校验器
 *
 * @author renxin
 * @email renxinzhiliangzhi@163.com
 * @date 2021/4/15 2:58 下午
 */
public class IPAddressLicenseValidator extends AbstractExitJVMLicenseValidator {

    @Override
    public String description() {
        return "IP 地址校验";
    }

    @Override
    protected ValidateResult validateResult(DLicenseContent content) {

        final boolean valid = Objects.isNull(content.getIpRule()) || content.getIpRule().test(MachineInfoUtil.getIpAddress());
        return new ValidateResult().setValid(valid).setLicenseValidator(this.getClass()).setDescription(valid ? "valid" : "IP地址不匹配");
    }
}
